using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using House.Server.Dto;
namespace House.Server.Repository
{
    /// <summary>
    /// 字典表的DAL操作层
    /// </summary>
    public class System_DictionaryRepository : GenericBaseRepository<Dictionary>
    {
        /// <summary>
        /// 字典两表链接显示
        /// </summary>
        /// <returns></returns>
        public List<System_DictionaryorDicState> link_show()
        {
            List<System_DictionaryorDicState> list = new List<System_DictionaryorDicState>();

            string sql = @"select * from t_Dictionary left join t_Dictionary_State on t_Dictionary.Dmenuid = t_Dictionary_State.DSid order by Did ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var x = cmd.ExecuteReader();
                    try
                    {
                        while (x.Read())
                        {
                            System_DictionaryorDicState d1 = new System_DictionaryorDicState();
                            d1.DSid = Convert.ToInt32(x["DSid"]);
                            d1.DictionaryName = x["DictionaryName"].ToString();
                            d1.Dmenuid = Convert.ToInt32(x["Dmenuid"]);
                            d1.DSname = x["DSname"].ToString();
                            d1.Did = Convert.ToInt32(x["Did"]);
                            d1.DSelectID = (x["DSelectID"]).ToString();
                            list.Add(d1);
                        }
                    }
                    finally
                    {
                        x.Close();
                    }
                }
                return list;
            }
        }

        /// <summary>
        /// 字典Dmenuid查询显示
        /// </summary>
        /// <returns></returns>
        public List<System_DictionaryorDicState> inquire_show(int id)
        {
            List<System_DictionaryorDicState> list = new List<System_DictionaryorDicState>();

            string sql = @"select * from t_Dictionary left join t_Dictionary_State on t_Dictionary.Dmenuid = t_Dictionary_State.DSid where Dmenuid = @id order by Did ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@id";
                    p.Value = id;
                    cmd.Parameters.Add(p);
                    var x = cmd.ExecuteReader();
                    try
                    {
                        while (x.Read())
                        {
                            System_DictionaryorDicState d1 = new System_DictionaryorDicState();
                            d1.DSid = Convert.ToInt32(x["DSid"]);
                            d1.DictionaryName = x["DictionaryName"].ToString();
                            d1.Dmenuid = Convert.ToInt32(x["Dmenuid"]);
                            d1.DSname = x["DSname"].ToString();
                            d1.Did = Convert.ToInt32(x["Did"]);
                            list.Add(d1);
                        }
                    }
                    finally
                    {
                        x.Close();
                    }
                }
                return list;
            }
        }

        /// <summary>
        /// 字典Did查询显示
        /// </summary>
        /// <returns></returns>
        public List<Dictionary> single_show(int id)
        {
            List<Dictionary> list = new List<Dictionary>();

            string sql = @"select * from t_Dictionary where Did = @id";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@id";
                    p.Value = id;
                    cmd.Parameters.Add(p);
                    var x = cmd.ExecuteReader();
                    try
                    {
                        while (x.Read())
                        {
                            Dictionary d1 = new Dictionary();
                            d1.Did = Convert.ToInt32(x["Did"]);
                            d1.DictionaryName = x["DictionaryName"].ToString();
                            d1.Dmenuid = Convert.ToInt32(x["Dmenuid"]);
                            list.Add(d1);
                        }
                    }
                    finally
                    {
                        x.Close();
                    }
                }
                return list;
            }
        }

    }
}
